home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW Related / MPW Script Tips 1.1.1 / Sample Scripts / RevertToVersion < prev    next >
Encoding:
Text File  |  1991-08-16  |  4.1 KB  |  118 lines  |  [TEXT/MPS ]

  1. #-----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    RevertToVersion
  3. #    MPW Shell Script
  4. #    Written by Gina Cherry • August 16, 1991
  5. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  6. #    
  7. #    Usage:
  8. #        RevertToVersion file [version]
  9. #        
  10. #    Function:
  11. #        RevertToVersion allows the user to revert to a previous version of a Projector file by copying 
  12. #        the old version of the file to a new revision.  If no version is specified on the command line, 
  13. #        RevertToRevision prompts the user for a version number.  It is necessary to create a new 
  14. #        revision of the file, because it is impossible to delete revisions from the top in Projector.  
  15. #        RevertToVersion also copies the comment and the task from the old version to the new version,
  16. #        and prepends a comment that the file has reverted to a previous revision.
  17. #-----------------------------------------------------------------------------------------------------------------------------------------------------
  18.     
  19.  
  20. #    If more than 2 parameters were given, write error message and exit script.
  21.     If {#} > 2
  22.         Echo "### Usage: {0} file [version]"
  23.         Exit 1
  24.     End >> Dev:StdErr
  25.  
  26. #    Don't exit on error.    
  27.     Set Exit 0
  28.  
  29. #    Initialize variables.    
  30.     Set revision ""
  31.     Set file ""
  32.  
  33. #    Loop through parameters.    
  34.     For item in {"parameters"}
  35.     
  36.     #    If the parameter is one or more digits followed by zero or more sequences of a letter and one or 
  37.     #    more digits (i.e. a legal version number) and if the revision variable has not been set, set 
  38.     #    revision to the parameter.
  39.         If "{item}" =~ /[0-9]+([a-z][0-9]+)*/
  40.             If {revision} == ""
  41.                 Set revision "{item}"
  42.         #    If revision has been set, write error message and exit script.
  43.             Else
  44.                 Echo "### Usage: {0} file [version]"
  45.                 Exit 1
  46.             End 
  47.         
  48.     #    Otherwise, if the file variable has not been set, set file to the parameter.
  49.         Else
  50.             If {file} == ""
  51.                 Set file "{item}"
  52.         #    If the file variable has been set, write error message and exit script.
  53.             Else
  54.                 Echo "### Usage: {0} file [version]"
  55.                 Exit 1
  56.             End 
  57.         End >> Dev:StdErr
  58.     End
  59.     
  60. #    If no file was specified on the command line, write error message and exit script.
  61.     If "{file}" == ""
  62.         Echo "### {0}: Must specify a file."
  63.         Echo "### Usage: {0} file [version]"
  64.         Exit 1
  65.     End >> Dev:StdErr
  66.  
  67. #    If no version was specified on the command line, prompt user for a version number.
  68.     If "{revision}" == ""
  69.         Set revision `Request "Version to which to revert:"` > Dev:Null
  70.     #    Exit if Cancel was chosen.
  71.         Exit If {revision} == ""
  72.     End
  73.     
  74. #    Check out the specified revision of the specified file.  If Checkout is not successful, exit script.
  75.     CheckOut "{file},{revision}" || Exit 2
  76.  
  77. #    Set info variable to the information returned by the ProjectInfo command.
  78.     Set info "`ProjectInfo -comments "{file},{revision}"`"
  79.     
  80. # Parse this information to extract the revision number, the task, and the comment.  Create 
  81. #    variables to remember this information.
  82.     If "{info}" =~ /[∂']*≈,([¬ ∂']+)®1[∂']*≈    Task: (≈)®2[ ]«5»Comment: (≈)®3/
  83.             Set task "{®2}"
  84.             Set comment "Reverted to revision {®1}.  {®3}"
  85.     End
  86.  
  87. #    Copy the contents of the old version of the projector file to a temporary file.
  88.     Duplicate -y "{file}" {0}.temp
  89.  
  90. #    Checkout a write-priveleged copy of the most recent version of the specified file.
  91.     CheckOut -m "{file}"
  92.  
  93. #    Compare the old version of the file with the newest version, discarding output.
  94.     Compare -b "{file}" {0}.temp > Dev:Null
  95.     
  96. #    Save the return value from the Compare command.
  97.     Set myStatus {Status}
  98.     
  99. #    If the 2 versions are the same, cancel the checkout.
  100.     If {myStatus} == 0
  101.         Echo "# Version {revision} matches the most recent version of the projector file {file}"
  102.     #    Cancel the file checkout, returning the projector database to its original state.
  103.         Checkout -y -cancel "{file}"
  104.         
  105. #    If the 2 versions are different, copy the text of the old version to the new version.  Close and 
  106. #    check in the file.
  107.     Else If {myStatus} == 2
  108.         Open {0}.temp
  109.         Copy •:∞ {0}.temp
  110.         Close -n {0}.temp
  111.         Open "{file}"
  112.         Paste •:∞ "{file}"
  113.         Close -y "{file}"
  114.         CheckIn "{file}" -cs "{comment}" -t "{task}"
  115.     End    
  116.  
  117. #    Delete the temporary file.    
  118.     Delete -y {0}.temp